package com.tczs;

import com.tczs.web.action.DataAction;
import com.tczs.web.action.DatabaseAction;
import com.tczs.web.action.LoginAction;
import com.tczs.web.action.TableAction;
import com.tczs.web.config.ConfigData;
import com.tczs.web.config.CustomerServerExecute;
import com.tczs.web.config.MessageEnZhData;
import com.tczs.dispatch.CollectAction;
import com.tczs.server.Config;
import com.tczs.server.SunServer;

import java.util.HashMap;
import java.util.Map;

public class StartConfig {

    public static void start(){
        //加载启动配置文件
        ConfigData configData = ConfigData.getConfigData();
        //加载国际化翻译配置文件
        MessageEnZhData.init();
        //装载项目模板路径,不执行默认为/api/
        // CollectAction.URL_PATTER = "/stran/api/";
        //装载项目中所有的action class文件
        loadActionClass();
        Config.setServerExecute(new CustomerServerExecute());
        //添加参数的特殊处理(解密),不自定义默认普通构建参数
        // Config.setGetMethodBuildParameter(new CustomerGetMethodBuildParameter());
        //开启服务
        SunServer.start(configData.getPort());
    }

    static void loadActionClass(){
        Map<Class,Object> map = new HashMap<>();
        map.put(DatabaseAction.class,new DatabaseAction());
        map.put(TableAction.class,new TableAction());
        map.put(DataAction.class,new DataAction());
        map.put(LoginAction.class,new LoginAction());
        CollectAction.setObjects(map);
        CollectAction.loadHandlers();
    }
}
